/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*                                                                    *
*        ***************************************************         *
*        *©2021-2031 LINUO Corporation All rights reserved *         *
*        ***************************************************         *
*                                                                    *
* FileName    : sys.c                                                *
*                                                                    *
* Author      : linus                                                *
*                                                                    *
* Email       : luoyaojun@sina.com                                   *
*                                                                    *
* Date        : 2024-3-27                                            *
*                                                                    *
* Description :                                                      *
*                                                                    *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "h_sys.h"
#include "rk_debug.h"
#include "rk_mpi_sys.h"
#include "sys.h"

static HT_S32 rk3588_sys_init(void)
{
    if (RK_MPI_SYS_Init() != RK_SUCCESS)
    {
        return -1;
    }

    return 0;
}

static HT_S32 rk3588_sys_exit(void)
{
    if (RK_MPI_SYS_Exit() != RK_SUCCESS)
    {
        return -1;
    }

    return 0;
}


static HT_S32 rk3588_sys_bind(HT_MOD_ID src_mid, HT_U32 src_dev, HT_U32 src_chn, HT_MOD_ID dst_mid, HT_U32 dst_dev,
                              HT_U32 dst_chn)
{
    MPP_CHN_S stSrcChn, stDstChn;

    stSrcChn.enModId = src_mid;
    stSrcChn.s32DevId = src_dev;
    stSrcChn.s32ChnId = src_chn;

    stDstChn.enModId = dst_mid;
    stDstChn.s32DevId = dst_dev;
    stDstChn.s32ChnId = dst_chn;

    return (RK_MPI_SYS_Bind(&stSrcChn, &stDstChn));
}

static HT_S32 rk3588_sys_unbind(HT_MOD_ID src_mid, HT_U32 src_dev, HT_U32 src_chn, HT_MOD_ID dst_mid, HT_U32 dst_dev,
                                HT_U32 dst_chn)
{
    MPP_CHN_S stSrcChn, stDstChn;

    stSrcChn.enModId = src_mid;
    stSrcChn.s32DevId = src_dev;
    stSrcChn.s32ChnId = src_chn;

    stDstChn.enModId = dst_mid;
    stDstChn.s32DevId = dst_dev;
    stDstChn.s32ChnId = dst_chn;

    //	printf("rk_sys_unbind %d %d %d -> %d %d %d\n", src_mid, src_dev, src_chn, dst_mid, dst_dev, dst_chn);

    return (RK_MPI_SYS_UnBind(&stSrcChn, &stDstChn));
}

static struct ht_sys_ops g_sys_ops = {
    .ht_sys_init = rk3588_sys_init,
    .ht_sys_bind = rk3588_sys_bind,
    .ht_sys_unbind = rk3588_sys_unbind,
    .ht_sys_exit = rk3588_sys_exit,

};

static HT_S32 __init rk3588_sys_register(void)
{
    HT_S32 ret = -1;
    struct rk3588_sys *plt_sys = (struct rk3588_sys *)calloc(1, sizeof(struct rk3588_sys));
    struct ht_sys *psys = NULL;

    if (!plt_sys)
        return -1;

    psys = &plt_sys->m_sys;

    psys->ops = &g_sys_ops;

    ht_sys_module_register(psys);

    return ret;
}
